package com.ruoyi.controller.system;
import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysChannelOut;
import com.ruoyi.system.service.ISysChannelOutService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出金通道Controller
 *
 * @author Ericcc
 * @date 2021-02-13
 */
@Controller
@RequestMapping("/system/channelOut")
public class SysChannelOutController extends BaseController
{
    private String prefix = "system/channelOut";

    @Autowired
    private ISysChannelOutService sysChannelOutService;

    @RequiresPermissions("system:channelOut:list")
    @GetMapping()
    public String out()
    {
        return prefix + "/channelOut";
    }

    /**
     * 查询出金通道列表
     */
    @RequiresPermissions("system:channelOut:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysChannelOut sysChannelOut)
    {
        startPage();
        List<SysChannelOut> list = sysChannelOutService.selectSysChannelOutList(sysChannelOut);
        return getDataTable(list);
    }

    /**
     * 导出出金通道列表
     */
    @RequiresPermissions("system:channelOut:export")
    @Log(title = "出金通道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysChannelOut sysChannelOut)
    {
        List<SysChannelOut> list = sysChannelOutService.selectSysChannelOutList(sysChannelOut);
        ExcelUtil<SysChannelOut> util = new ExcelUtil<SysChannelOut>(SysChannelOut.class);
        return util.exportExcel(list, "out");
    }

    /**
     * 新增出金通道
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出金通道
     */
    @RequiresPermissions("system:channelOut:add")
    @Log(title = "出金通道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysChannelOut sysChannelOut)
    {
        sysChannelOut.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(sysChannelOutService.insertSysChannelOut(sysChannelOut));
    }

    /**
     * 修改出金通道
     */
    @GetMapping("/edit/{channelOutId}")
    public String edit(@PathVariable("channelOutId") Long channelOutId, ModelMap mmap)
    {
        SysChannelOut sysChannelOut = sysChannelOutService.selectSysChannelOutById(channelOutId);
        mmap.put("sysChannelOut", sysChannelOut);
        return prefix + "/edit";
    }

    /**
     * 修改保存出金通道
     */
    @RequiresPermissions("system:channelOut:edit")
    @Log(title = "出金通道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysChannelOut sysChannelOut)
    {
        sysChannelOut.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(sysChannelOutService.updateSysChannelOut(sysChannelOut));
    }

    /**
     * 删除出金通道
     */
    @RequiresPermissions("system:channelOut:remove")
    @Log(title = "出金通道", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysChannelOutService.deleteSysChannelOutByIds(ids));
    }
}
